<?php
$solo = FALSE;
if ( count(get_included_files())===1 ){
	$solo = TRUE;
	require_once('../bpc_load.php');
}

if ( !isset($bra_id) )
	if ( isset($_GET['bra_id']) )
		$bra_id = $_GET['bra_id'];
	else
		$bra_id = 1;
$sql_nb = sprintf("SELECT count( cli_id ) as nb
FROM clients
WHERE cli_bra_id=%s", $bra_id);
$sql_tab = sprintf("SELECT cli_id, cli_bra_id, cli_nom, uti_id, uti_code, uti_nom, uti_prenom, zon_id, zon_nom, zon_code, cli_ville, count( mac_id ) AS mac_nb
FROM clients CLI
JOIN zones ZON ON ZON.zon_id = CLI.cli_zon_id
JOIN utilisateurs UTI ON UTI.uti_id = CLI.cli_uti_id
LEFT JOIN machines MAC ON MAC.mac_cli_id = CLI.cli_id
GROUP BY cli_id
HAVING CLI.cli_bra_id=%s", $bra_id);
			
class cli_rap extends _BphNaviSQL{
	public function SetTr(){
		$this->Addtr(LNG_NOM, 'cli_nom', 30);
		$this->Addtr(LNG_ZONE, 'zon_code', 20);
		$this->Addtr(LNG_UTILISATEURS, 'uti_nom,uti_prenom', 20);
		$this->Addtr(LNG_VILLE, 'cli_ville', 20);
		$this->Addtr(LNG_MACHINES, 'mac_nb', 10);
	}
	
	public function FillTr($row){
		return Array(	new BpcAClient($row['cli_id'], $row['cli_nom']),
						new BpcAZone($row['zon_id'], $row['zon_nom'], $row['zon_code']),
						new BpcAUtilisateur($row['uti_id'], $row['uti_nom'], $row['uti_prenom'], $row['uti_code']),
						$row['cli_ville'],
						$row['mac_nb']);
	}
}

$navi = new cli_rap('cli_rap', 'ajax/cli_rap.ajax.php?bra_id='.$bra_id, $sql_nb, $sql_tab);

if ( $solo ){
	echo $navi->InnerCode(0);
}
?>
